package com.prp.gwt.client.widgets.user.article;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.History;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.prp.gwt.client.user.article.ArticleHistoryHandler;
import com.prp.gwt.client.vo.Entity;

public class EntityItem extends HorizontalPanel {

	VerticalPanel vPanel = new VerticalPanel();

	public EntityItem(final Entity entity) {
		{
			Image image = new Image(entity.getPic());
			add(image);
			image.addStyleName("entity-item-pic");
			add(vPanel);
			addStyleName("entity-item");
		}
		{
			FlexTable table = new FlexTable();
			table.setCellPadding(5);
			Label label = new Label("主题:");
			label.addStyleName("entity-item-label");
			table.setWidget(0, 0, label);
			HTML html = new HTML(entity.getCategoryName());
			html.addStyleName("entity-item-content");
			table.setWidget(0, 1, html);
			label = new Label("分类:");
			label.addStyleName("entity-item-label");
			table.setWidget(1, 0, label);
			html = new HTML(entity.getChildCategoryName());
			html.addStyleName("entity-item-content");
			table.setWidget(1, 1, html);
			label = new Label("名称:");
			label.addStyleName("entity-item-label");
			table.setWidget(2, 0, label);
			final HTML name = new HTML("<a>" + entity.getName() + "</a>");
			name.addClickHandler(new ClickHandler(){
				@Override
				public void onClick(ClickEvent event) {
					History.newItem(ArticleHistoryHandler.PREFIX_ENTITY+entity.getId());
				}
			});
			name.setStylePrimaryName("entity-item-content");
			table.setWidget(2, 1, name);
			{
				table.setWidget(0, 2, new Label("已有" + entity.getReplyNum()
						+ "人推荐"));
				html = new HTML("<a>查看主题帖</a>");
				html.addClickHandler(new ClickHandler(){
					@Override
					public void onClick(ClickEvent event) {
						History.newItem(ArticleHistoryHandler.PREFIX_ENTITY+entity.getId());
					}
				});
				table.setWidget(1, 2, html);
				html = new HTML("<a>我来推荐</a>");
				html.addClickHandler(new ClickHandler(){
					@Override
					public void onClick(ClickEvent event) {
						History.newItem(ArticleHistoryHandler.PREFIX_ADD_RECOMMEND+entity.getId());
					}
				});
				table.setWidget(2,2, html);
			}
			vPanel.add(table);
		}
	}

}
